package com.sl.core.config;

import cn.hutool.core.util.StrUtil;
import org.apache.ibatis.logging.slf4j.Slf4jImpl;
import org.apache.ibatis.logging.stdout.StdOutImpl;

public class CustomerSlf4jImpl extends Slf4jImpl {

    private StdOutImpl stdOut;

    private String clazz;

    public CustomerSlf4jImpl(String clazz) {
        super(clazz);
        stdOut = new StdOutImpl(clazz);
        this.clazz = clazz;
    }


    @Override
    public boolean isDebugEnabled() {
        return stdOut.isDebugEnabled();
    }

    @Override
    public boolean isTraceEnabled() {
        return stdOut.isTraceEnabled();
    }

    @Override
    public void error(String s, Throwable e) {
        if(StrUtil.containsAnyIgnoreCase(clazz,"SaTokenMapper","DefaultSqlSession","LogFactory","SqlSessionUtils","SpringManagedTransaction")){
            return;
        }
        stdOut.error(s,e);
        super.error(s,e);
    }

    @Override
    public void error(String s) {
        if(StrUtil.containsAnyIgnoreCase(clazz,"SaTokenMapper","DefaultSqlSession","LogFactory","SqlSessionUtils","SpringManagedTransaction")){
            return;
        }
        stdOut.error(s);
        super.error(s);
    }

    @Override
    public void debug(String s) {
        if(StrUtil.containsAnyIgnoreCase(clazz,"SaTokenMapper","DefaultSqlSession","LogFactory","SqlSessionUtils","SpringManagedTransaction")){
            return;
        }
        stdOut.debug(s);
        super.debug(s);
    }

    @Override
    public void trace(String s) {
        if(StrUtil.containsAnyIgnoreCase(clazz,"SaTokenMapper","DefaultSqlSession","LogFactory","SqlSessionUtils","SpringManagedTransaction")){
            return;
        }
        stdOut.trace(s);
        super.trace(s);
    }

    @Override
    public void warn(String s) {
        if(StrUtil.containsAnyIgnoreCase(clazz,"SaTokenMapper","DefaultSqlSession","LogFactory","SqlSessionUtils","SpringManagedTransaction")){
            return;
        }
        stdOut.warn(s);
        super.warn(s);
    }
}
